﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using LiuYan.Entity;
using LiuYan.Service;

namespace LiuYan.Web.Areas.Admin.Controllers
{
    public class EvaluateController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Window(int id)
        {
            ViewData["id"] = id;
            ViewData["Name"] = new GoodService().GetGoodName(id);
            return View();
        }

        public int EditPingJian(FormCollection form)
        {
            var img = form["img"].Split(',');
            TB_Evaluate entity = new TB_Evaluate();
            entity.Id = Convert.ToInt32(form["id"]);
            entity.Gid = Convert.ToInt32(form["gid"]);
            entity.Rnk = Convert.ToInt32(form["rnk"]);
            entity.Img1 = img.Length >= 1 ? img[0] : "";
            entity.Img2 = img.Length >= 2 ? img[1] : "";
            entity.Img3 = img.Length >= 3 ? img[2] : "";
            if (form["time"] != "")
            {
            entity.Date = Convert.ToDateTime(form["time"]);
            }
            else
            {
             entity.Date = DateTime.Now;
            }
            entity.Del = 0;
            entity.UserId =0;
            entity.Text = form["content"];
            entity.OrderNo = "";
            entity.PlName = form["name"];
            return new EvaluateService().Edit(entity);
        }
        public string GetList(int pageIndex, int pageCount, string title,int gid)
        {
            return JsonConvert.SerializeObject(new EvaluateService().GetList(pageIndex, pageCount,gid));
        }

        public int Del(string ids)
        {
            return new BaseService().Dels(ids, "TB_Evaluate", false);
        }

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public string UploadImg()
        {
            HttpFileCollection file = System.Web.HttpContext.Current.Request.Files;
            int num = file.Count;
            string imgPath = "";
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string fileName = file[0].FileName.Split('\\').Last();
            imgPath = "/Content/pjimg/" + Convert.ToInt64(ts.TotalSeconds) + "." + fileName.Split('.').Last();
            string path = Server.MapPath(imgPath);
            file[0].SaveAs(path);
            return "{'status':'1','path':'" + imgPath + "'}";
        }

    }
}
